import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class ImageUtils{

}

/// 加载本地资源图片
Widget loadAssetImage(String name, {double width, double height, BoxFit fit = BoxFit.fill ,Color color,double scale}) {
  return Image.asset(
    getImgPath(name),
    height: height,
    width: width,
    scale: scale,
    fit: fit,
    color: color,
  );
}

/// 加载本地资源图片
Widget loadAssetImageAll(String name, {double all, BoxFit fit = BoxFit.fill ,Color color,double scale}) {
  return Image.asset(
    getImgPath(name),
    height: all,
    width: all,
    scale: scale,
    fit: fit,
    color: color,
  );
}

///加载本地 image
AssetImage loadAssetsImageType(String name, {double width, double height, BoxFit fit,Color color,double scale}) {
  return AssetImage(
    getImgPath(name),
  );
}

///加载网络 image
NetworkImage loadNetworkType(String url) {
  return NetworkImage(
    url,
  );
}

/// 加载网络图片
// Widget loadNetworkImage(String imageUrl,
//     {double width,
//       double height,
//       BoxFit fit: BoxFit.cover,
//       String holderImg: "none"}) {
//   if (TextUtil.isEmpty(imageUrl)) {
//     return loadAssetImage(holderImg, height: height, width: width, fit: fit);
//   }
//   return CachedNetworkImage(
//     imageUrl: imageUrl,
//     width: width,
//     height: height,
//     fit: fit,
//   );
// }

// Widget loadNetworkImageAll(String imageUrl,
//     {double width,
//       double all,
//       BoxFit fit: BoxFit.cover,
//       String holderImg: "none"}) {
//   if (TextUtil.isEmpty(imageUrl)) {
//     return loadAssetImage(holderImg, height: all, width: all, fit: fit);
//   }
//   return CachedNetworkImage(
//     imageUrl: imageUrl,
//     width: all,
//     height: all,
//     fit: fit,
//   );
// }

// ImageProvider getImageProvider(String imageUrl, {String holderImg: "none"}) {
//   if (TextUtil.isEmpty(imageUrl)) {
//     return AssetImage(getImgPath(holderImg));
//   }
//   return CachedNetworkImageProvider(imageUrl);
// }

String getImgPath(String name, {String format: 'png'}) {
  return 'assets/images/$name.$format';
}
